<%@page import="com.mesystem.dto.RegistroDTO"%>
<%@page import="com.mesystem.util.Util"%>
<%@page import="com.mesystem.managedbean.RegistroMB"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="java.util.Formatter"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>  
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.util.List"%>
<%@page import="javax.faces.application.Application"%>
<%@page import="javax.faces.context.FacesContext"%>
<%@ page contentType="application/vnd.ms-excel"%>

<%
	FacesContext context = FacesContext.getCurrentInstance();
	Object myBean = context
			.getELContext()
			.getELResolver()
			.getValue(context.getELContext(), null,
					"registroMB");
	RegistroMB registroMB = (RegistroMB) myBean;
	
	SimpleDateFormat sdfFormatoFecha = new SimpleDateFormat(
			"dd/MM/yyyy HH:mm:ss");

	String sFechahora = sdfFormatoFecha.format(new Date()); 
	 
    String variable = registroMB.getAnio() + registroMB.getMes() + "_" + System.currentTimeMillis();
    
%>
<%
	response.setHeader("Content-Disposition", "attachment; filename=\""
			+ "Registros" + "_"
			+ variable + ".xls\"");
	
	
	String fechaActualizacion="";
	String horaActualizacion = "";
	String fechaReg = "";
	String horaReg = "";


%>
<table cellspacing="1" cellpadding="4" >

	<tr>
		<td colspan="5" align="center" style="text-decoration: underline;">Listado
			de registro de horas</td>
	</tr>
	<tr>
		<td colspan="5" ></td>
	</tr>

	<tr>
		<td>Anio:</td>
		<td style="text-align: left;font-weight: bold;"><%=registroMB.getAnio()%></td>
		<td>&nbsp;</td>
		<td>Mes:</td>
		<td style="text-align: left;font-weight: bold;"><%=Util.getDescMes(registroMB.getMes())%></td>
		
	</tr>
	<tr>
		<td>Usuario:</td>
		<td style="text-align: left;font-weight: bold;"><%=RegistroMB.getObjectInSession("nomusua")%></td>
		<td>&nbsp;</td> 
		<td>Fecha:</td>
		<td style="text-align: left;font-weight: bold;"><%=sFechahora%></td>
	</tr>
	<tr>
		<td># Registros:</td>
		<td style="text-align: left;font-weight: bold;"><%=registroMB.getiCanRegTablaPrincipal()%></td>
		<td></td>
		<td></td>
		<td></td>
	</tr>
</table>
<br />
<br />

<table style="padding-top: 10px; border: 1px solid black;" bordercolor="#C0C0C0" cellspacing="1">
	<tr bgcolor="#C0C0C0">
		<td style="border: 1px solid black;">Item</td>
		<td style="border: 1px solid black;">Anio</td>
		<td style="border: 1px solid black;"">Mes</td>
		<td style="border: 1px solid black;">Dia</td>
		<td style="border: 1px solid black;">Horas</td>
		<td style="border: 1px solid black;">Revistas</td>
		<td style="border: 1px solid black;">Revisitas</td>
		<td style="border: 1px solid black;">Folletos</td>
	</tr>
	<%
		List<RegistroDTO> lstRegistros = registroMB.getLstRegistros();
			if (!lstRegistros.isEmpty()) {
				
				for (RegistroDTO reg : lstRegistros) {
					
	%>
	<tr>
		<td  style="border: 1px solid black;"><%=reg.getId()%></td>
		<td  style="border: 1px solid black;"><%=reg.getAnio()%></td>
		<td style="border: 1px solid black;"><%=reg.getDescMes()%></td>
		<td style="border: 1px solid black;"><%=reg.getDia()%></td>
		<td style="border: 1px solid black;"><%=reg.getHoras()%></td>
		<td style="border: 1px solid black;"><%=reg.getRevistas()%></td>
		<td style="border: 1px solid black;"><%=reg.getRevisitas()%></td>
		<td style="border: 1px solid black;"><%=reg.getFolletos()%></td>
	</tr>
	<%
		}
			} else {
	%>
	<tr>
		<td colspan="4" style="border: 1px solid black;">No hay datos</td>

	</tr>
	<%
		}
	%>
</table>